//
//  CJAllCompanyUserController.m
//  Boss
//
//  Created by admin on 2018/9/20.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "CJAllCompanyUserController.h"
#import "CJFirmUserListModel.h"
#import "CJFirmUserCell.h"
@interface CJAllCompanyUserController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@end

@implementation CJAllCompanyUserController
-(NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadUser];
    [self setupUI];
}

-(void)setupUI
{
    self.navigationItem.title = @"公司成员";
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"CJFirmUserCell" bundle:nil] forCellReuseIdentifier:@"CJFirmUserCell"];
    self.tableView.rowHeight = 72;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CJFirmUserCell *cell =[tableView dequeueReusableCellWithIdentifier:@"CJFirmUserCell" forIndexPath:indexPath];
    if (!cell) {
        cell =[[NSBundle mainBundle]loadNibNamed:@"CJFirmUserCell" owner:nil options:nil].firstObject;
    }
    CJFirmUserListModel *model = self.dataArray[indexPath.row];
    [cell setModel:model];
    
    
    
    return cell;
    
    
    
    return nil;
}

-(void)loadUser
{
    WEAKSELF
    [WYHttpServer getFirmUserWithFirmId:self.firmID SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
       
        if (success) {
            [weakSelf.dataArray addObjectsFromArray:[CJFirmUserListModel getUserListModelFromJson:response[@"result"]]];
            [weakSelf.tableView reloadData];
        }else{
            [weakSelf toast:errorMessage];
        }
        
        
        
    }];
}
- (UITableView *)tableView
{
    if (_tableView == nil) {
        CGRect frame = CGRectMake(0, self.navHeight, kScreenWidth, kScreenHeight-self.navHeight);
        _tableView = [[UITableView alloc] initWithFrame:frame
                                                  style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
    }
    return _tableView;
}

@end
